package com.example.allinone;

import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.view.Menu;
import android.widget.TextView;

public class ContractActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		try {
			super.onCreate(savedInstanceState);
			// setContentView(R.layout.activity_contract);
			TextView textView = new TextView(this);
			String string = "";
			ContentResolver contentResolver = getContentResolver();
			Cursor cursor = contentResolver.query(
					ContactsContract.Contacts.CONTENT_URI, null, null, null,
					null);
			while (cursor.moveToNext()) {
				String contact = cursor.getString(cursor
						.getColumnIndex(PhoneLookup.DISPLAY_NAME));

				// String number = cursor.getString(cursor
				// .getColumnIndex(PhoneLookup.NUMBER));
				string += (contact + "\n");
			}
			cursor.close();
			textView.setText(string);
			setContentView(textView);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.contract, menu);
		return true;
	}

}
